using PKGames.Localization;
using System;
using System.Runtime.CompilerServices;

namespace PKGames.Plugins.AskForReviewPlugin
{
	public static class ReviewController
	{
		private static class CallbackMessages
		{
			public static readonly string YesButtonSelected = "YesButtonSelected";

			public static readonly string LaterButtonSelected = "LaterButtonSelected";

			public static readonly string NoButtonSelected = "NoButtonSelected";
		}

		private const string PopupTitleKey = "ReviewPopupTitle";

		private const string PopupMessageKey = "ReviewPopupMsg";

		private const string PopupYesButtonKey = "ReviewPopupYesButton";

		private const string PopupLaterButtonKey = "ReviewPopupLaterButton";

		private const string PopupNoButtonKey = "ReviewPopupNoButton";

		private const int SequenceDaysNeeded = 5;

		[CompilerGenerated]
		private static Action<string> _003C_003Ef__mg_0024cache0;

		[CompilerGenerated]
		private static Action<string> _003C_003Ef__mg_0024cache1;

		public static void AskForReview()
		{
			if (!ReviewPreferences.ShouldntShowAgain && UserStatistics.SequenceOpenDays >= 5 && (DateTime.Today - ReviewPreferences.LastTimeShowed).TotalDays > (double)ReviewPreferences.DaysUntilShow)
			{
				AskForReviewPluginFactory.Create().AskForReview(SuccessCallback, ErrorCallback, MonoSingleton<LocationProvider>.Instance.GetLocalizedString("ReviewPopupTitle"), MonoSingleton<LocationProvider>.Instance.GetLocalizedString("ReviewPopupMsg"), MonoSingleton<LocationProvider>.Instance.GetLocalizedString("ReviewPopupYesButton"), MonoSingleton<LocationProvider>.Instance.GetLocalizedString("ReviewPopupNoButton"), MonoSingleton<LocationProvider>.Instance.GetLocalizedString("ReviewPopupLaterButton"));
				ReviewPreferences.ShowTimes++;
				ReviewPreferences.LastTimeShowed = DateTime.Today;
			}
		}

		public static void SuccessCallback(string message)
		{
			if (message == CallbackMessages.YesButtonSelected)
			{
				ReviewPreferences.ShouldntShowAgain = true;
			}
			else
			{
				ReviewPreferences.DaysUntilShow = 30;
			}
			ReviewAnalyticsEvent reviewAnalyticsEvent = new ReviewAnalyticsEvent(message);
			reviewAnalyticsEvent.Log();
		}

		public static void ErrorCallback(string error)
		{
			ReviewPreferences.DaysUntilShow = 7;
			ReviewAnalyticsEvent reviewAnalyticsEvent = new ReviewAnalyticsEvent(error);
			reviewAnalyticsEvent.Log();
		}
	}
}
